/*
 * FNISVGEditor - JavaScript - based editor for SVG graphics 
 * Copyright (C) 2008 - 2009 Antti Leppä / Foyt
 * http://www.foyt.fi
 * 
 * License: 
 * 
 * Licensed under GNU Lesser General Public License Version 2.1 or later (the "LGPL") 
 * http://www.gnu.org/licenses/lgpl.html
 */
FNISVGEditorElementStylingUtils = {
  setStyles: function (element, styles) {
    for (var i in styles)
      element.style.setProperty(i, styles[i], null);      
  },
  getStyle: function (element, style) { 
	var value = element.style.getPropertyValue(style);
	if (value.startsWith("rgb")) {
	  var c = value.substring(value.indexOf('(') + 1, value.lastIndexOf(')')).split(',');
	  var b = parseInt(c.pop());
	  var g = parseInt(c.pop());
	  var r = parseInt(c.pop());
		  
	  value = '#' + [r,g,b].invoke('toColorPart').join('');
 	}
	
	return value; 
  }, 
  setTemporaryStyle: function(element, styles){
    if (!element._tmpStyleStack) 
      element._tmpStyleStack = new Array();
    
    var oldStyles = new Object();
    
    for (var i in styles)
      oldStyles[i] = element.style.getPropertyValue(i);      
    
    this.setStyles(element, styles);
    
    element._tmpStyleStack.push(oldStyles);
  },
  removeTemporaryStyle: function(element) {
    if (!element._tmpStyleStack) {
      var styles = element._tmpStyleStack.pop();
      
      this.setStyles(element, styles);
      
      if (element._tmpStyleStack.length <= 0) 
        element._tmpStyleStack = null;
    }
  }
};
 